package cn.dragon.eatingfish;

import java.applet.Applet;
import java.applet.AudioClip;
import java.io.File;
import java.net.MalformedURLException;

public class GameMusic {
    AudioClip clip = null;

    public static void main(String[] args) {
        GameMusic gameMusic = new GameMusic();
        gameMusic.palyLoopMusic("music/Test1.wav");
    }

    public AudioClip getAudioClip() {
        return this.clip;
    }

    public void setAudioClip(AudioClip clip) {
        this.clip = clip;
    }

    public void play() {//一次播放
        if (getAudioClip() != null) {
            getAudioClip().play();
        }
    }

    public void loop() {//循环
        if (getAudioClip() != null) {
            getAudioClip().loop();
        }
    }

    public void stop() {//停止
        if (getAudioClip() != null) {
            getAudioClip().stop();
        }
    }

    public void playMusic(String fil) {
        GameMusic gameMusic = new GameMusic();
        try {
            gameMusic.setAudioClip(Applet.newAudioClip((new File(fil)).toURL()));
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        gameMusic.play();

    }

    public void stopMusic(String fil) {
        GameMusic gameMusic = new GameMusic();
        try {
            gameMusic.setAudioClip(Applet.newAudioClip((new File(fil)).toURL()));
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        gameMusic.stop();
    }

    public void palyLoopMusic(String fil) {
        GameMusic gameMusic = new GameMusic();
        try {
            gameMusic.setAudioClip(Applet.newAudioClip((new File(fil)).toURL()));
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        gameMusic.loop();
    }

}
